<?php
!defined('P_W') && exit('Forbidden');
$baseUrl = "$admin_file?adminjob=mode&admintype=house_sale";

if (empty($action)) {
	House::LoadClass('houseurl', 'utility', false);
	InitGP(array('subject', 'village', 'username', 'top_urgent', 'user'),'GP');
	InitGP(array('platetype', 'areatype', 'state', 'page'),'GP',2);
	$userService = L::loadClass('UserService', 'user');
	$user && $uid = $userService->getUserIdByUserName($user);
	!$page && $page = 1;	
	$perpage = 20;
	$SaleService = House::LoadService('SecondSaleService');
	$areas = $SaleService->getFieldsByType('area');//所属区域
	$plates = $SaleService->getPlateByAreaId($areatype);
	$top_urgent != 'none' ? ($top_urgent && $expand[$top_urgent] = 1) : $expand['istop'] = $expand['isurgent']= 0 ;//扩展参数
	$user && $expand['uid'] = $uid;
	$state && $expand['state'] = $state;
	$index = array('areatype' => $areatype,'platetype'=>$platetype);//索引参数
	$keywords = array($subject);//关键字
	$url = $baseUrl . '&subject=' . $subject . '&areatype=' . $areatype . '&plate=' . $plate . '&user=' . $user . '&top_urgent=' . $top_urgent . '&state=' . $state;
	$returnurl = $url . '&page=' . $page;
	list($total,$result) = $SaleService->getDetailList($index, 'DESC', 'posttime',$keywords, $page, $perpage,$expand);	
	$pages = numofpage($total, $page, ceil($total/$perpage), $url.'&');//分页信息
	include PrintMode('sale.run');//渲染模板	
	
}elseif($action == 'getplate'){
	$SaleService = House::LoadService('SecondSaleService');
	S::gp(array('areatype'),'GP',2);
	$plates = $SaleService->getPlateByAreaId($areatype);//所有板块
	echo pwJsonEncode($plates);
	ajax_footer();
}elseif($action == 'delete'){
	InitGP(array('houseids','returnurl'));
	if(empty($houseids)){
		adminmsg('operate_error');
	}
	$SaleService = House::LoadService('SecondSaleService');
	
	$retv = $SaleService->delete($houseids);
	if($retv == false) showMsg('删除失败!');
	adminmsg('operate_success',$returnurl);
}
